﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using WorkflowEngine.EntityFrameworkCore;
using WorkflowEngine.Entitys;
using WorkflowEngine.IRepositorys;
using Microsoft.EntityFrameworkCore;
namespace WorkflowEngine.Repositorys
{

    public class ActivityInstanceRepository : EfCoreRepository<WorkflowEngineDbContext, ActivityInstance, Guid>
     , IEfCoreRepository<ActivityInstance>, IActivityInstanceRespository
    {
        public ActivityInstanceRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public override async Task<IQueryable<ActivityInstance>> GetQueryableAsync()
        {
            return await base.GetQueryableAsync();
        }
    }

    public class ActivityTaskInstanceRepository : EfCoreRepository<WorkflowEngineDbContext, ActivityTaskInstance, Guid>
     , IEfCoreRepository<ActivityTaskInstance>, IActivityTaskInstanceRespository
    {
        public ActivityTaskInstanceRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
            base.GetQueryableAsync();
        }

        public override async Task<IQueryable<ActivityTaskInstance>> GetQueryableAsync()
        {
            return await base.GetQueryableAsync();
        }
    }

    public class BillCodeRepository : EfCoreRepository<WorkflowEngineDbContext, BillCode, Guid>
 , IEfCoreRepository<BillCode>, IBillCodeRespository
    {
        public BillCodeRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public override async Task<IQueryable<BillCode>> GetQueryableAsync()
        {
            return await base.GetQueryableAsync();
        }
    }

    public class ObjectAppRepository : EfCoreRepository<WorkflowEngineDbContext, ObjectApp, Guid>
, IEfCoreRepository<ObjectApp>, IObjectAppRespository
    {
        public ObjectAppRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public override async Task<IQueryable<ObjectApp>> GetQueryableAsync()
        {
            return await base.GetQueryableAsync();
        }
    }

    public class WorkflowAppRepository : EfCoreRepository<WorkflowEngineDbContext, WorkflowApp, Guid>
, IEfCoreRepository<WorkflowApp>, IWorkflowAppRespository
    {
        public WorkflowAppRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task<IQueryable<WorkflowApp>> GetQueryableAsync(bool detail)
        {
            var query = await base.GetQueryableAsync();
            if (detail)
                query = query.Include(m => m.ObjectApps);
            return query;
        }
    }

    public class WorkflowInstanceRepository : EfCoreRepository<WorkflowEngineDbContext, WorkflowInstance, Guid>
, IEfCoreRepository<WorkflowInstance>, IWorkflowInstanceRespository
    {
        public WorkflowInstanceRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public   async Task<IQueryable<WorkflowInstance>>  GetQueryableAsync(bool detail)
        {
            var query = await base.GetQueryableAsync();
            if (detail)
                query = query.Include(m => m.ActivityInstances)
                    .Include(m => m.ActivityTaskInstances).ThenInclude(M => M.WorkTask);
            return query;
        }
    }

    public class WorkTaskRepository : EfCoreRepository<WorkflowEngineDbContext, WorkTask, Guid>
, IEfCoreRepository<WorkTask>, IWorkTaskRespository
    {
        public WorkTaskRepository(IDbContextProvider<WorkflowEngineDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public override async Task<IQueryable<WorkTask>> GetQueryableAsync()
        {
            return await base.GetQueryableAsync();
        }
    }

}
